def Programma(n):
    t=True
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            t=False
    return t
    
    
s=input()
alf=['zero','one','two','three','four','five','six','seven','eight','nine']
s=s.split()
if(s[0] in alf) and (s[1] in alf) and (s[2] in alf):
    chifra=alf.index(s[0])*100+alf.index(s[1])*10+alf.index(s[2])
    if Programma(chifra):
        p=chifra
    else:
        for i in range(chifra-1,2,-1):
            if Programma(i):
                p=i
                break
        for i in range(chifra+1,1500):
            if Programma(i) and (chifra-p)>(i-chifra):
                p=i
                break
    print(p)
else: print('Wrong input')